package com.xiaoshuidi.cloud.module.member.enums.coupon;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.annotation.IEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Alex
 * @description 需要发送短信的公司
 * @date 2022/12/5 16:45
 */
@Getter
@AllArgsConstructor
public enum CouponTypeEnum implements IEnum<Integer> {

	RESERVATION_DISCOUNT(1,"YD","预定优惠"),
	OLD_WITH_NEW_DISCOUNT(2,"LDX","老带新优惠"),
	NEW_SIGNING_DISCOUNT(3,"XQY","新签约优惠"),
	INTERNAL_EMPLOYEE_DISCOUNT (4,"NBYG","内部员工优惠"),
	OTHER_DISCOUNT (5,"QT","其他优惠"),
	;
	@EnumValue
	private final Integer num;
	private final String code;
	private final String desc;

	private static Map<Integer, CouponTypeEnum> enumMap = new HashMap<>();

	static {
		CouponTypeEnum[] values = CouponTypeEnum.values();
		for (CouponTypeEnum value : values) {
			enumMap.put(value.getNum(), value);
		}
	}

	@Override
	public Integer getValue() {
		return num;
	}
	public static String getCouponTypeByCode(int code) {
		CouponTypeEnum[] couponTypeEnums = values();
		for (CouponTypeEnum couponTypeEnum : couponTypeEnums) {
			if (couponTypeEnum.num==code) {
				return couponTypeEnum.code;
			}
		}
		return null;
	}

	public static CouponTypeEnum getEnum(Integer num){
		return enumMap.get(num);
	}

	public static String getDesc(Integer num){
		CouponTypeEnum couponTypeEnum = getEnum(num);
		return couponTypeEnum == null ? null : couponTypeEnum.getDesc();
	}
}
